//加载组件
layui.config({
    base: './js/'  //导入xm-select.js
}).extend({
    xmSelect: 'xm-select'
}).use(['xmSelect', 'layer','form'], function() {
    var xmSelect = layui.xmSelect,
        layer = layui.layer,
        form = layui.form;
    var demo2 = xmSelect.render({
        el: '#modId',
        model: { label: { type: 'text' } },
        radio: true,
        clickClose: true,
        tree: {
            show: true,
            strict: false,
            expandedKeys: [ -1 ],
        },
        height: 'auto',
        data: []
    })

    //权限树回显
    $.ajax({
        url: "/logisticsModule/selectAll",
        dataType: 'json',//数据类型
        type: 'GET',//类型
        timeout: 5000,//超时
        success: function (resp) {
            demo2.update({
                data: resp.data,
                autoRow: true,
            })
        }
    })
    //监听权限选择框
    $("#modId").bind("DOMNodeInserted",function (){
        $.ajax({
            url:"/logisticsModule/selectOne",
            data: {
                modId:demo2.getValue('valueStr')},
            dataType:'json',//数据类型
            type:'GET',//类型
            timeout:5000,//超时
            success:function(resp){
                $("#modName").val(resp.modName);
                $("#modUrl").val(resp.modUrl);
            }
        })
    })

//角色信息回显
    let id = GetQueryString('modId');
    if(id){
        let url ="/logisticsModule/selectOne";
        let data ={modId:id};
        $.get(url,data,function (resp){
            demo2.setValue([resp.modId]);
            form.val('example',resp);
        })
    }



    $("#up").on("click",function (){
        $.ajax({
            url:"/logisticsModule/updateMod",
            data: {
                modName:$("#modName").val(),
                modUrl:$("#modUrl").val(),
                modId:demo2.getValue('valueStr')},
            dataType:'json',//数据类型
            type:'GET',//类型
            timeout:5000,//超时
            success:function(resp){
                parent.layer.msg(resp.mes);//父页面消息提示
                layerClose();//关闭弹窗
            }
        })
    })
    //关闭按钮
    $("#close_btn").on("click", function () {
        layerClose();
    });
})

//在子页面中关闭弹出层
function layerClose(){
    var index= parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}